package com.noble.glamour.bean.center.user.light;

import android.os.Parcel;
import android.os.Parcelable;

import com.noble.library.base.bean.BaseData;
import com.noble.glamour.module.logic.config.AreaConfig;
import com.noble.glamour.module.logic.config.InfoConfig;

import org.json.JSONObject;

/**
 * 轻量用户资料： 后续替代UserInfoLightweight
 */
public class UserLight extends BaseData implements Parcelable {
    private long uid;
    private int age;             // 年龄
    private String nickname;
    private String avatar;
    private int gender;          // 1 男 2 女
    private String birthday;     // 生日
    private int height;          // 身高
    private String weight;       // 体重
    private String star;         // 星座
    private String aboutme;         // 内心独白
    private String province;      // 完整省份
    private String city;          // 完整城市
    private String provinceName;  // 展示省份
    private String cityName;      // 展示城市
    private int scity;            // 城市代码
    private int sprovince;        // 省份代码

    private boolean isVip;
    private int photoNum;


    @Override
    public void parseJson(String jsonStr) {
        InfoConfig infoConfig = InfoConfig.getInstance();
        JSONObject jsonObject = getJsonObject(jsonStr);

        // user_base表数据
        if (!jsonObject.isNull("user_base")) {
            String base = jsonObject.optString("user_base");
            JSONObject baseObject = getJsonObject(base);

            this.setUid(baseObject.optLong("Id"));
            this.setAvatar(baseObject.optString("Avatar"));
            this.setNickname(baseObject.optString("NickName"));
            this.setGender(baseObject.optInt("Gender"));
            this.setAge(baseObject.optInt("Age"));
            this.setBirthday(baseObject.optString("Birthday"));
            this.setWeight(infoConfig.getWeight().getShowWithSubmit(baseObject.optInt("Weight")));
            this.setStar(infoConfig.getStar().getShowWithSubmit(baseObject.optInt("Star")));
            this.setAboutme(baseObject.optString("AboutMe"));

            int pid = baseObject.optInt("Province");
            int cit = baseObject.optInt("City");
            this.setScity(cit);
            this.setSprovince(pid);
            this.setProvince(AreaConfig.getInstance().getProvinceByID(pid));
            this.setCity(AreaConfig.getInstance().getCityByID(cit));
            this.setProvinceName(AreaConfig.getInstance().getProvinceNameByID(pid));
            this.setCityName(AreaConfig.getInstance().getCityNameByID(cit));
        }

        // user_detail数据表
        if (!jsonObject.isNull("user_detail")) {
            String detail = jsonObject.optString("user_detail");
            JSONObject detailObject = getJsonObject(detail);

            this.setVip(detailObject.optBoolean("IsVip"));
            this.setPhotoNum(detailObject.optInt("PhotoNum"));
        }
    }

    /**
     * 性别判断
     */
    public boolean isMan() {
        return gender != 2;
    }

    /**
     * 判断是否是vip
     */
    public boolean isVip() {
        return isVip;
    }

    public void setVip(boolean vip) {
        isVip = vip;
    }

    public int getPhotoNum() {
        return photoNum;
    }

    public void setPhotoNum(int photoNum) {
        this.photoNum = photoNum;
    }

    public long getUid() {
        return uid;
    }

    public void setUid(long uid) {
        this.uid = uid;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public int getGender() {
        return gender;
    }

    public void setGender(int gender) {
        this.gender = gender;
    }

    public String getBirthday() {
        return birthday;
    }

    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public String getWeight() {
        return weight;
    }

    public void setWeight(String weight) {
        this.weight = weight;
    }

    public String getStar() {
        return star;
    }

    public void setStar(String star) {
        this.star = star;
    }

    public String getAboutme() {
        return aboutme;
    }

    public void setAboutme(String aboutme) {
        this.aboutme = aboutme;
    }

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getProvinceName() {
        return provinceName;
    }

    public void setProvinceName(String provinceName) {
        this.provinceName = provinceName;
    }

    public String getCityName() {
        return cityName;
    }

    public void setCityName(String cityName) {
        this.cityName = cityName;
    }

    public int getScity() {
        return scity;
    }

    public void setScity(int scity) {
        this.scity = scity;
    }

    public int getSprovince() {
        return sprovince;
    }

    public void setSprovince(int sprovince) {
        this.sprovince = sprovince;
    }

    @Override
    public String toString() {
        return "UserLight{" +
                "uid=" + uid +
                ", age=" + age +
                ", nickname='" + nickname + '\'' +
                ", avatar='" + avatar + '\'' +
                ", gender=" + gender +
                ", birthday='" + birthday + '\'' +
                ", height=" + height +
                ", weight='" + weight + '\'' +
                ", star='" + star + '\'' +
                ", aboutme='" + aboutme + '\'' +
                ", province='" + province + '\'' +
                ", city='" + city + '\'' +
                ", provinceName='" + provinceName + '\'' +
                ", cityName='" + cityName + '\'' +
                ", scity=" + scity +
                ", sprovince=" + sprovince +
                '}';
    }

    public UserLight() {
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(this.uid);
        dest.writeInt(this.age);
        dest.writeString(this.nickname);
        dest.writeString(this.avatar);
        dest.writeInt(this.gender);
        dest.writeString(this.birthday);
        dest.writeInt(this.height);
        dest.writeString(this.weight);
        dest.writeString(this.star);
        dest.writeString(this.aboutme);
        dest.writeString(this.province);
        dest.writeString(this.city);
        dest.writeString(this.provinceName);
        dest.writeString(this.cityName);
        dest.writeInt(this.scity);
        dest.writeInt(this.sprovince);
        dest.writeByte(this.isVip ? (byte) 1 : (byte) 0);
        dest.writeInt(this.photoNum);
    }

    protected UserLight(Parcel in) {
        this.uid = in.readLong();
        this.age = in.readInt();
        this.nickname = in.readString();
        this.avatar = in.readString();
        this.gender = in.readInt();
        this.birthday = in.readString();
        this.height = in.readInt();
        this.weight = in.readString();
        this.star = in.readString();
        this.aboutme = in.readString();
        this.province = in.readString();
        this.city = in.readString();
        this.provinceName = in.readString();
        this.cityName = in.readString();
        this.scity = in.readInt();
        this.sprovince = in.readInt();
        this.isVip = in.readByte() != 0;
        this.photoNum = in.readInt();
    }

    public static final Creator<UserLight> CREATOR = new Creator<UserLight>() {
        @Override
        public UserLight createFromParcel(Parcel source) {
            return new UserLight(source);
        }

        @Override
        public UserLight[] newArray(int size) {
            return new UserLight[size];
        }
    };
}
